#ifndef QNOTEVIEWWINDOW_H
#define QNOTEVIEWWINDOW_H

#include <MApplicationPage>
#include <MButton>
#include <MWidget>
#include "ui/MNoteViewWindow.h"
#include "QvernoteWindow.h"
#include "QvernoteAPI.h"
#include "QEnmlReader.h"
#include "ui/MClickableImage.h"
#include "QNoteEditWindow.h"
#include "widgets/CNoteDisplayWidget.h"
#include "CNoteDisplayManager.h"

class QNoteViewWindow : public QvernoteWindow
{
    Q_OBJECT

public:
    QNoteViewWindow(const Note& note, MApplicationPage *parent = 0);
    ~QNoteViewWindow();

    //void showEvent ( QShowEvent * );
    //void gestureEvent(QGestureEvent *);
    void panGestureEvent(QGestureEvent* event, QPanGesture* gesture);
    void swipeGestureEvent(QGestureEvent *event, QSwipeGesture *gesture);
    //void pinchGestureEvent(QGestureEvent* event, QPinchGesture* gesture);

    Note& getNote() { return noteDisplayManager->GetCurrentNote(); }
    //void mousePressEvent(QMouseEvent* e);
    //void mouseReleaseEvent(QMouseEvent* e);
    //void mouseMoveEvent(QMouseEvent* e);
    //void loadNextNote(Note& note);
    //void loadPrevNote(Note& note);

public slots:
    void onAnimationDone(Qt::GestureType gestureType) { qDebug() << "back to grab"; grabGesture(gestureType); }
    void startEditor();
    //void resizeWebView();
    void openLink(QUrl);

    //void zoominView();
    //void zoomoutView();
    //void emailNote();
    //void loadNextNote();
    //void loadPrevNote();
    void showNoteMap();

    bool loadNote();
    //void displayNote();

    //void displayNavigationControls();
    //void hideNavigationControls();

//#ifdef Q_WS_MAEMO_5
    void toggleFullScreen();
//#endif

    //void onFavoriteClicked();
    //void backgroundLoad();
    //void startBackgroundTask() { m_pBackgroundJob->start(); }
    //void noteLoadFinished();

    /* JS API functions */
    void handleResource(QString);

    //bool backgroundJobCallback() { return loadNote(); }
    //void jobDoneCallback() { displayNote(); }
    //void jobFailedCallback() { displayError(trUtf8("Unable to load note"), QString(m_hEvernote->getLastErrorString().c_str())); }

signals:
    void startEditorSignal(Note&, QEnmlReader*);

private:
        //void clearNote();
        //void initNavigationControls();
        //void updateHeader();


private:
    Ui::QNoteViewWindowClass ui;
    Note m_Note;
    QvernoteAPI* m_hEvernote;
    //shared_ptr<QEnmlReader> enmlReader;
    //MClickableImage	*clZoomin, *clZoomout, *clNext, *clPrev, *clFullscreen, *clEdit, *clEmail, *clMap;
    //QTimer* navigationControlTimer;
    //QPoint	mousePos;
    //bool isMousePressed;
    //bool isNavControlsVisible;
    //QPropertyAnimation* webViewSlide;
    //QRectF	savedWebViewGeometry;
    //bool	slideLeft;
    shared_ptr<QNoteEditWindow> m_pNoteEditWindow;
    MApplicationPage* m_parent;
    //CNoteDisplayWidget* testNoteDisplayWidget;
    CNoteDisplayManager* noteDisplayManager;
};

class QResourceHandlerDialog : public MDialog
{
	Q_OBJECT

public:
	QResourceHandlerDialog(Note& note, QString resourceHash, MWidget* parent = 0);

public slots:
	void storeResource();
    void previewResource();

private:
    Note m_Note;
    QString m_resourceHash;
    QGraphicsGridLayout* layout;
    MButton bSave, bPreview;
    MWidget centralWidget;
};
#endif // QNOTEVIEWWINDOW_H
